package piconode.ext;

import piconode.core.operator.ActivationFunction;
import piconode.toolbox.Display;

/*
 * Created on 6 janv. 2005
 * bredeche(at)lri(point)fr
 * 
 */

public class ActivationFunction_PiecewiseLinear extends ActivationFunction {

	private double _xmin;
	private double _xmax;

	/**
	 * initialize a piecewise linear function - useful if a min and max
	 * threshold is needed to be set. Warning the function only grows. f(x<xmin)=>xmin ;
	 * f(x>xmax)=>xmax; f(xmin<x<xmax)=>x
	 * 
	 * @param __minY
	 * @param __x1
	 * @param __x2
	 * @param __maxY
	 */
	public ActivationFunction_PiecewiseLinear(int __xmin, int __xmax) {
		if (__xmin > __xmax)
			Display.critical("" + this.getClass().getName() + " - piecewise linear function must grow.");
		this._xmin = __xmin;
		this._xmax = __xmax;
	}

	/**
	 * 
	 * @param __value
	 *            the incoming x value
	 * @return f(x) defined as f(x<xmin)=>xmin ; f(x>xmax)=>xmax; f(xmin<x<xmax)=>x
	 */
	@Override
	public double applyFunction(double __value) // another well-known non-linear
	// activation function
	{
		if (__value < this._xmin)
			return (this._xmin);
		else if (__value > this._xmax)
			return (this._xmax);
		else
			return (__value);
	}

	public double applyDerivativeFunction(double __value) // f'(x) = ...
	{
		System.out.println("PieceWiseLinearActivationFunction::applyDerivativeOfActivationFunction(-) - undefined");
		System.exit(-1);
		return (-1);
	}

}
